const hre = require("hardhat");

async function main() {
  console.log("Testing BSCLaunchPad deployment on local network...");
  
  // Deploy mock router for testing
  console.log("\n=== Deploying Mock PancakeSwap Router ===");
  
  // For testing, we'll deploy a simplified mock
  const MockRouter = await hre.ethers.getContractFactory("MockRouter");
  const mockRouter = await MockRouter.deploy(
    "0x0000000000000000000000000000000000000000", // Mock WBNB
    "0x0000000000000000000000000000000000000001"  // Mock Factory
  );
  await mockRouter.waitForDeployment();
  console.log("MockRouter deployed to:", await mockRouter.getAddress());
  
  console.log("\n=== Deploying BSCLaunchPad ===");
  
  // Deploy BSCLaunchPad with mock router
  const BSCLaunchPad = await hre.ethers.getContractFactory("BSCLaunchPad");
  const launchPad = await BSCLaunchPad.deploy(await mockRouter.getAddress());
  await launchPad.waitForDeployment();
  
  console.log("BSCLaunchPad deployed to:", await launchPad.getAddress());
  
  // Test basic functionality
  console.log("\n=== Testing Basic Functionality ===");
  
  // Check initial values
  const platformFee = await launchPad.platformFeePercent();
  const nextLaunchId = await launchPad.nextLaunchId();
  const owner = await launchPad.owner();
  const router = await launchPad.pancakeRouter();
  const factory = await launchPad.pancakeFactory();
  
  console.log("Platform Fee:", platformFee.toString(), "basis points");
  console.log("Next Launch ID:", nextLaunchId.toString());
  console.log("Owner:", owner);
  console.log("PancakeSwap Router:", router);
  console.log("PancakeSwap Factory:", factory);
  
  // Test contract constants
  const minTarget = await launchPad.MIN_TARGET();
  const maxTarget = await launchPad.MAX_TARGET();
  const maxFee = await launchPad.MAX_FEE();
  const launchDuration = await launchPad.LAUNCH_DURATION();
  const graduationThreshold = await launchPad.GRADUATION_THRESHOLD();
  
  console.log("\n=== Contract Constants ===");
  console.log("Min Target:", hre.ethers.formatEther(minTarget), "BNB");
  console.log("Max Target:", hre.ethers.formatEther(maxTarget), "BNB");
  console.log("Max Fee:", maxFee.toString(), "basis points");
  console.log("Launch Duration:", launchDuration.toString(), "seconds");
  console.log("Graduation Threshold:", graduationThreshold.toString(), "%");
  
  // Test bonding curve constants
  const basePrice = await launchPad.CURVE_BASE_PRICE();
  const priceIncrement = await launchPad.CURVE_PRICE_INCREMENT();
  const tokensForCurve = await launchPad.TOKENS_FOR_CURVE();
  const tokensForLiquidity = await launchPad.TOKENS_FOR_LIQUIDITY();
  
  console.log("\n=== Bonding Curve Parameters ===");
  console.log("Base Price:", hre.ethers.formatEther(basePrice), "BNB");
  console.log("Price Increment:", hre.ethers.formatEther(priceIncrement), "BNB");
  console.log("Tokens for Curve:", hre.ethers.formatEther(tokensForCurve));
  console.log("Tokens for Liquidity:", hre.ethers.formatEther(tokensForLiquidity));
  
  console.log("\n✓ All contracts deployed and initialized successfully!");
  
  console.log("\n=== Deployment Summary ===");
  console.log("MockRouter:", await mockRouter.getAddress());
  console.log("BSCLaunchPad:", await launchPad.getAddress());
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });